#include "ZeroConsole.h"

#include <iostream>
#include <cstring>

const int ZeroConsole::C_MaxCmdLen = 32;

ZeroConsole::ZeroConsole(ZeroSystem *zsys)
{
	mOpType = ZCON_Local;
	mZSys = zsys;
}

ZeroConsole::~ZeroConsole()
{
}

void ZeroConsole::startCommandLoop()
{
	int len;
	char buf[C_MaxCmdLen], *cmd, *param;
	if (!mZSys) {
		std::cout << "Error: ZeroSystem has not yet initialized" << std::endl;
		return;
	}
	while (true) {
		if (mOpType == ZCON_Local) {
			std::cout << "Local > ";
			std::cout.flush();
		}
		std::cin.getline(buf, C_MaxCmdLen);
		len = std::strlen(buf);
		if (!len)
			break;
		for (cmd = buf;*cmd == ' ';cmd++);
		for (param = cmd;*param && *param != ' ';param++);
		*param++ = 0;
		if (strcmp(cmd, "exit") == 0) {
			mZSys->stop();
			break;
		} else if (strcmp(cmd, "start") == 0) {
			mZSys->start();
		} else if (strcmp(cmd, "stop") == 0) {
			mZSys->stop();
		} else if (strcmp(cmd, "status") == 0) {
			mZSys->dumpStatus();
		} else if (strcmp(cmd, "") == 0) {
		} else if (strcmp(cmd, "") == 0) {
		} else if (strcmp(cmd, "") == 0) {
		} else {
		}
	}
}
